package jvm;

import org.junit.Test;




/**
 * JVM 注册钩子函数
 * Created mangcao with 2019/2/20 15:10
 * Description:
 */
public class RunTimeTest {

    @Test
    public void RuntimeTest() {
        Runtime.getRuntime().exit(1);
    }


    @Test
    public void addShutdownHookTest() {

        Runtime.getRuntime().addShutdownHook(new Thread(() -> System.out.println("The hook is executing")));

        System.out.println("The application is going to be stopped");

        //强行退出， 不会执行hooks
        Runtime.getRuntime().halt(1);
    }


}
